package com.ruoyi.proSystem.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.proSystem.domain.ProItem;
import com.ruoyi.proSystem.service.IProItemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 基本信息Controller
 *
 * @author ruoyi
 * @date 2024-07-29
 */
@RestController
@RequestMapping("/item")
public class ProItemController extends BaseController
{
    @Autowired
    private IProItemService proItemService;

    /**
     * 查询基本信息列表
     */
    @RequiresPermissions("proSystem:item:list")
    @GetMapping("/list")
    public TableDataInfo list(ProItem proItem)
    {
        startPage();
        List<ProItem> list = proItemService.selectProItemList(proItem);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出基本信息列表
     */
    @RequiresPermissions("proSystem:item:export")
    @Log(title = "基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProItem proItem)
    {
        List<ProItem> list = proItemService.selectProItemList(proItem);
        ExcelUtil<ProItem> util = new ExcelUtil<ProItem>(ProItem.class);
        util.exportExcel(response, list, "基本信息数据");
    }

    /**
     * 获取基本信息详细信息
     */
    @RequiresPermissions("proSystem:item:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(proItemService.selectProItemById(id));
    }

    /**
     * 新增基本信息
     */
    @RequiresPermissions("proSystem:item:add")
    @Log(title = "基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Integer add(@RequestBody ProItem proItem)
    {
        proItemService.insertProItem(proItem);
        return  proItem.getId();
    }

    /**
     * 修改基本信息
     */
    @RequiresPermissions("proSystem:item:edit")
    @Log(title = "基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProItem proItem)
    {
        System.out.println(proItem+"++++++++++++++++");
        return toAjax(proItemService.updateProItem(proItem));
    }

    /**
     * 删除基本信息
     */
    @RequiresPermissions("proSystem:item:remove")
    @Log(title = "基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(proItemService.deleteProItemByIds(ids));
    }
}
